<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="container-div">
    <div class="btn-group hidden-xs" id="toolbar" role="group">
        <a class="btn btn-outline btn-success btn-rounded" onclick="$.operate.add()"
           shiro:hasPermission="beautyflower:word:add">
            <i class="fa fa-plus"></i> 新增
        </a>
        <a class="btn btn-outline btn-danger btn-rounded" onclick="$.operate.removeAll()"
           shiro:hasPermission="beautyflower:word:remove">
            <i class="fa fa-trash-o"></i> 删除
        </a>
    </div>

    <div class="col-sm-12 select-table table-striped">
        <table id="bootstrap-table" data-mobile-responsive="true"></table>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('beautyflower:word:edit')}]];
    var removeFlag = [[${@permission.hasPermi('beautyflower:word:remove')}]];
    var releaseFlag = [[${@permission.hasPermi('beautyflower:word:release')}]];
    var cancelReleaseFlag = [[${@permission.hasPermi('beautyflower:word:cancelRelease')}]];
    var prefix = ctx + "system/word";

    $(function () {
        var options = {
            id: "id",
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "系统文档管理",
            search: false,
            columns: [{
                checkbox: true
            },
                {
                    field: 'type',
                    title: '键/类型'
                },
                {
                    field: 'label',
                    title: '标签'
                },
                {
                    field: 'title',
                    title: '标题'
                },
                {
                    field: 'mode',
                    title: '内容类型',
                    formatter: function (value, row, index) {
                        return {'TEXT': '文本', 'FILE': '文件', 'LINK': '连接', 'HTML': '页面'}[value];
                    }
                },
                {
                    field: 'release',
                    title: '发布时间'
                },
                {
                    field: 'status',
                    title: '发布状态',
                    formatter: function (value, row, index) {
                        return ['', '未发布', '待发布', '已发布'][value];
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        if (row.status !== undefined && row.status === 3) {
                            actions.push('<a class="btn btn-warning btn-xs ' + cancelReleaseFlag + '" href="#" onclick="cancelRelease(\'' + row.id + '\')" style="margin-left: 4px"><i class="fa fa-remove"></i>取消</a>');
                        } else {
                            actions.push('<a class="btn btn-info btn-xs ' + releaseFlag + '" href="#" onclick="release(\'' + row.id + '\')" style="margin-left: 4px"><i class="fa fa-edit"></i>发布</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function release(id) {
        $.modal.confirm("确定该条信息吗？", function () {
            $.modal.loading("正在处理中，请稍后...");
            $.ajax({
                    url: prefix + '/release',
                    type: "post",
                    dataType: "json",
                    data: {id: id},
                    success: function (result) {
                        $.operate.ajaxSuccess(result);
                    }
                }
            );
        });
    }

    function cancelRelease(id) {
        $.modal.confirm("确定取消发布该条信息吗？", function () {
                $.modal.loading("正在处理中，请稍后...");
                $.ajax({
                        url: prefix + '/cancelRelease',
                        type: "post",
                        dataType: "json",
                        data: {id: id},
                        success: function (result) {
                            $.operate.ajaxSuccess(result);
                        }
                    }
                );
            }
        );
    }
</script>
</body>
</html>